///\todo upgrade

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef __BUOLA_PYTHON_CTYPE_H_
#define __BUOLA_PYTHON_CTYPE_H_

#include <buola/python.h>

#include <unordered_map>

#include <buola/python/cmethodpool.h>
#include <buola/python/cmemberpool.h>

namespace buola { namespace python {

typedef CObjectBase*(*TPythonNewObject)(PyObject*);

class CType : public CMethodPool,public CMemberPool
{
public:
    CType(const std::string &pModuleName,const std::string &pName,TPythonNewObject,CType *pInherited=nullptr);

    void SetStrFunc(reprfunc);
    void SetReprFunc(reprfunc);
    void SetCompFunc(richcmpfunc);
    void SetLenFunc(lenfunc);
    void SetIndexFunc(ssizeargfunc);
    void SetHashFunc(hashfunc);
    void SetGetAttrFunc(getattrofunc);
    void SetSetAttrFunc(setattrofunc);
    void SetDirFunc(PyCFunction);
    void SetCallFunc(ternaryfunc);

    void AddOperator(int pOp,unaryfunc pFunction);
    void AddOperator(int pOp,binaryfunc pFunction);
    void AddOperator(int pOp,ternaryfunc pFunction);

    void Init();

    static CObjectBase *GetNew(PyTypeObject *pType,PyObject *pArgs);
    
    YObject GetPythonObject()   {   return YObject((PyObject*)mType);  }

    PyTypeObject *mType;

    std::string mModuleName;
    std::string mName;
    std::string mDoc;

    TPythonNewObject mNewObject;

    static std::unordered_map<PyTypeObject*,CType*> mAllTypes;
};

/*namespace python*/ } /*namespace buola*/ }

#endif
